package com.test.byteDance;

import java.util.Scanner;

public class Byte2019_2_2 {
    public long arrestPlan(int[] ints, int d) {
        int left = 0;
        int right = 2;
        long res = 0;
        long num;
        while (left < ints.length - 2) {
            while ((right < ints.length) && (ints[right] - ints[left] <= d)) {
                right++;
            }
            // 因为上面的right++;最后会多加一次1，所以这里减一
            right -= 1;
            num = right - left;
            res += num * (num - 1) / 2;
            left++;
        }
        return res % 99997867;
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int D = scanner.nextInt();
        int[] ints = new int[N];

        for (int i = 0; i < N; i++) {
            ints[i] = scanner.nextInt();
        }
        Byte2019_2_2 byte2019_2_2 = new Byte2019_2_2();
        System.out.println(byte2019_2_2.arrestPlan(ints, D));
    }
}
